package edu.cuit.jead.mynetdisk.service;

import edu.cuit.jead.mynetdisk.dao.FileMapper;
import edu.cuit.jead.mynetdisk.dao.UserMapper;
import edu.cuit.jead.mynetdisk.entity.Fileinfo;
import edu.cuit.jead.mynetdisk.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

@Service
public class Fileservice {
    @Autowired
    FileMapper fileMapper;
    public Integer getID(String email){
        User finduser=new User();
        finduser=fileMapper.getUserByEmail(email);
        if(finduser!=null) {
            Integer id=null;
            id=finduser.getId().intValue();
            return id;
        }
    return null;}
    public Fileinfo saveFile(Fileinfo newfile){
        Fileinfo file =new Fileinfo();
        file.setEmail(newfile.getEmail());
        file.setPath(newfile.getPath());
        file.setUserID(newfile.getUserID());
        file.setCollected(0);
        file.setRecycled(0);
        file.setShared(0);
        file.setSize(newfile.getSize());
        file.setUploadtime(fileMapper.getCurrentTime());
        file.setLastedit(fileMapper.getCurrentTime());
        System.out.println(file);
        fileMapper.insertfile(file);

        return file;
    }
    public List<Fileinfo> filedata(String email){
        List<Fileinfo> files=new ArrayList<>();
        files=fileMapper.getFileByEmail(email);
        return files;
    }
    public int deleteFile(String path){
        int i= fileMapper.deleteFile(path);
        return i;
    }
    public Integer getRecycled(String path){
        return fileMapper.getRecycled(path);
    }
    public Long getSize(String path){
        return fileMapper.getSize(path);
    }
    public Long getUsedSpace(String email){
        return fileMapper.getUsedSpace(email);
    }
    public Long getTotalSpace(String email){
        return fileMapper.getTotalSpace(email);
    }
    public Integer updateRecycled(String path,Integer recycled){
        return fileMapper.updateRecycled(path,recycled);
    }
    public int updateCollect(String path,Integer collect){
        return fileMapper.updateCollect(path,collect);
    }
    public Integer getCollected(String path){
        return fileMapper.getCollected(path);
    }
    public int updateUsedSpace(String email,Long usedspace){
        return fileMapper.updateUsedSpace(email,usedspace);
    }
}
